﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using Assesment.Library;
using Assesment.Library.DomainObject.Administration.Catalog;
using Assesment.Library.Enum;
using Assesment.Library.Interfaces;
using SIPO.Library.DomainObject.Administration.Catalog;

namespace Assesment.Library.DataAccess.Administration.Catalog
{
    public partial class ManagerialKeyBehaviourDetailRepo
    {
        public List<ManagerialKeyBehaviourDetail> GetListByManagerialKeyBehaviourID(int ManagerialKeyBehaviourID)
        {
            List<ManagerialKeyBehaviourDetail> tt = new List<ManagerialKeyBehaviourDetail>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    //cmd.CommandText = "SELECT ManagerialDetailID, ManagerialKeyBehaviourID, KeyBehaviourDetailID, CreatedDate, CreatedBy, UpdatedDate, UpdatedBy FROM master.ManagerialKeyBehaviourDetail";
                    cmd.CommandText = "SP_ManagerialKeyBehaviourDetail_SelectBy_ManagerialKeyBehaviourID";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@ManagerialKeyBehaviourID", SqlDbType.Int).Value = ManagerialKeyBehaviourID;
                    try
                    {
                        conn.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (dr.Read())
                            {
                                ManagerialKeyBehaviourDetail t = new ManagerialKeyBehaviourDetail();
                                t.ManagerialDetailID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID] == DBNull.Value ? 0 : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID].ToString());
                                t.ManagerialKeyBehaviourID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID].ToString());
                                t.KeyBehaviourDetailID = dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID].ToString());
                                t.CreatedDate = dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate].ToString());
                                t.CreatedBy = dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy].ToString();
                                t.UpdatedDate = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate].ToString());
                                t.UpdatedBy = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy].ToString();
                                tt.Add(t);
                                t.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }
                }
            }
            return tt;
        }

        public List<ManagerialKeyBehaviourDetail> GetListByPositionID_CompetencyDesc(int PositionID,string CompetencyDesc)
        {
            List<ManagerialKeyBehaviourDetail> tt = new List<ManagerialKeyBehaviourDetail>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    //cmd.CommandText = "SELECT ManagerialDetailID, ManagerialKeyBehaviourID, KeyBehaviourDetailID, CreatedDate, CreatedBy, UpdatedDate, UpdatedBy FROM master.ManagerialKeyBehaviourDetail";
                    cmd.CommandText = "SP_KeyBehaviourDetail_SelectByPositionID_CompetencyDesc";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@PositionID", SqlDbType.Int).Value = PositionID;
                    cmd.Parameters.Add("@CompetencyDesc", SqlDbType.VarChar).Value = CompetencyDesc;
                    try
                    {
                        conn.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (dr.Read())
                            {
                                ManagerialKeyBehaviourDetail t = new ManagerialKeyBehaviourDetail(true);
                                t.ManagerialDetailID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID] == DBNull.Value ? 0 : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID].ToString());
                                t.ManagerialKeyBehaviourID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID].ToString());
                                t.KeyBehaviourDetailID = dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID].ToString());
                                t.CreatedDate = dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate].ToString());
                                t.CreatedBy = dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy].ToString();
                                t.UpdatedDate = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate].ToString());
                                t.UpdatedBy = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy].ToString();

                                t.KeyBehaviourDetail.KeyBehaviourName = dr[KeyBehaviourDetail.Fields.KeyBehaviourName] == DBNull.Value ? string.Empty : dr[KeyBehaviourDetail.Fields.KeyBehaviourName].ToString();
                                tt.Add(t);
                                t.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }
                }
            }
            return tt;
        }


       

        public List<ManagerialKeyBehaviourDetail> GetListByAssesmentPositionID(int AssesmentPositionID, string CompetencyDesc)
        {
            List<ManagerialKeyBehaviourDetail> tt = new List<ManagerialKeyBehaviourDetail>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    //cmd.CommandText = "SELECT ManagerialDetailID, ManagerialKeyBehaviourID, KeyBehaviourDetailID, CreatedDate, CreatedBy, UpdatedDate, UpdatedBy FROM master.ManagerialKeyBehaviourDetail";
                    cmd.CommandText = "SP_AssesmentPositionDetail_SelectByAssesmentPositionID";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@AssesmentPositionID", SqlDbType.Int).Value = AssesmentPositionID;
                    cmd.Parameters.Add("@CompetencyDesc", SqlDbType.VarChar).Value = CompetencyDesc;
                    
                    try
                    {
                        conn.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (dr.Read())
                            {
                                ManagerialKeyBehaviourDetail t = new ManagerialKeyBehaviourDetail(true);
                                t.ManagerialDetailID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID] == DBNull.Value ? 0 : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialDetailID].ToString());
                                t.ManagerialKeyBehaviourID = dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.ManagerialKeyBehaviourID].ToString());
                                t.KeyBehaviourDetailID = dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID] == DBNull.Value ? (int?)null : int.Parse(dr[ManagerialKeyBehaviourDetail.Fields.KeyBehaviourDetailID].ToString());
                                t.CreatedDate = dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.CreatedDate].ToString());
                                t.CreatedBy = dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.CreatedBy].ToString();
                                t.UpdatedDate = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[ManagerialKeyBehaviourDetail.Fields.UpdatedDate].ToString());
                                t.UpdatedBy = dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy] == DBNull.Value ? string.Empty : dr[ManagerialKeyBehaviourDetail.Fields.UpdatedBy].ToString();

                                t.KeyBehaviourDetail.KeyBehaviourName = dr[KeyBehaviourDetail.Fields.KeyBehaviourName] == DBNull.Value ? string.Empty : dr[KeyBehaviourDetail.Fields.KeyBehaviourName].ToString();
                                tt.Add(t);
                                t.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }
                }
            }
            return tt;
        }		
    }
}
